package com.aaa.demo03;

/**
 * @author ${崔灿}
 * @date 2022/10/31 17:37
 **/

public class MyTicket implements Runnable{
    private static int ticket=100;
    private static Object ticket1=new Object();
    @Override
    public void run() {

        while (true) {
            synchronized (ticket1) {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖了一张票，剩余"+--ticket );
                }
                else {
                    break;
                }
            }
        }
    }
}
